/**
 * There are code generation
 */
package com.neusoft.lohas.modules.shop.dao;

import org.springframework.stereotype.Repository;

import com.neusoft.lohas.common.persistence.BaseDao;
import com.neusoft.lohas.common.persistence.Parameter;
import com.neusoft.lohas.modules.ivm.entity.merchant.Merchant;
import com.neusoft.lohas.modules.ivm.entity.order.ShoppingCart;

/**
 * 购物车DAO接口
 * @author Jackie.Liu
 * @version 2014-12-16
 */
@Repository
public class ShoppingCartDao extends BaseDao<ShoppingCart> {
	
	public ShoppingCart findByCart(ShoppingCart cart){
		return getByHql("from ShoppingCart where merchant.id = :p1 and user.id = :p2 and product.id = :p3 and delFlag = :p4", new Parameter(cart.getMerchant().getId(), cart.getUser().getId(), cart.getProduct().getId(), Merchant.DEL_FLAG_NORMAL));
	}
	
	public int clearShoppingCart(ShoppingCart cart){
		String sql = "update ivm_shopping_cart set del_flag='1' where merchant_id=:p1 and user_id=:p2 and del_flag=:p3";
		return updateBySql(sql, new Parameter(cart.getMerchant().getId(), cart.getUser().getId(), ShoppingCart.DEL_FLAG_NORMAL));
	}
}
